home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Monsieur Cinéma.ifs < prev    next >
Encoding:
Text File  |  2004-12-10  |  33.1 KB  |  772 lines

  1. // GETINFO SCRIPTING
  2. // Monsieur CinΘma + affiche CinΘfil
  3. (***************************************************
  4.  *  Movie importation script for:                  *
  5.  *  Monsieur CinΘma + affiche CinΘfil              *
  6.  *  version 4.6 (c) 2004 scorpion7552              *
  7.  * grand merci α Antoine Potten pour son aide lors *
  8.  * de la mise au point de ce script                *
  9.  *                                                 *
  10.  * merci aux auteurs des scripts initiaux          *
  11.  *  Monsieur CinΘma, http://cinema.tiscali.fr      *
  12.  *  (c) 2002 Antoine Potten    antoine@buypin.com  *
  13.  * et                                              *
  14.  *  CinΘfil.com , http://www.cinefil.com           *
  15.  *  (c) 2003 Danone-KiD                            *
  16.  *                                                 *
  17.  *  For use with Ant Movie Catalog 3.4.3           *
  18.  *  www.ant.be.tf/moviecatalog ╖╖╖ www.buypin.com  *
  19.  *                                                 *
  20.  *  The source code of the script can be used in   *
  21.  *  another program only if full credits to        *
  22.  *  script author and a link to Ant Movie Catalog  *
  23.  *  website are given in the About box or in       *
  24.  *  the documentation of the program               *
  25.  ***************************************************)
  26.  
  27. program MonsieurCinema;
  28. const
  29. { ImportPicture
  30.    0   aucune image importΘe
  31.    1   import image MrCinema seule
  32.    2   import image Cinefil seule
  33.    3   import de toutes les images
  34. }                           
  35.    ImportPicture = 1;      // pour faire plaisir α antp
  36. { FullStory
  37.    True: importer l'histoire complΦte
  38.    False: importer le rΘsumΘ (s'il existe, sinon import histoire complΦte)
  39. }
  40.    FullStory = False;
  41. { ImportAnecdote
  42.    True: importer l'anecdote α la suite de l'avis de la rΘdaction (commentaires)
  43.    False: ne pas importer l'anecdote
  44. }
  45.    ImportAnecdote = False;
  46. { FullGenerique
  47.    True: importer le gΘnΘrique complet
  48.    False: importer le gΘnΘrique de la page essentiel
  49. }
  50.    FullGenerique = False;
  51. {ExternalPictures 
  52.    True: Les images seront stockΘes en tant que fichiers dans le mΩme dossier que le catalogue
  53.    False: Les images seront stockΘes dans le catalogue (seulement pour les fichiers .amc)
  54.    ExternalPictures = False;
  55. { Always
  56.   note: la remise α vide d'un champ ne fonctionne pas avec amc 3.4.3
  57.          sera corrigΘ dans amc 3.5
  58.    False: Θcrire les champs seulement si la valeur lue est non vide
  59.    True: Θcrire les champs dans tous les cas (sauf affiche)
  60. }
  61.    Always = False;
  62. // fin des paramΦtres user
  63.    MrCinemaUrl = 'http://cinema.tiscali.fr/';
  64.    MrCinemaUrlFilm = MrCinemaUrl + 'fichefilm.aspx';
  65.    MrCinemaUrlLook = MrCinemaUrl + 'recherche.aspx?file=http&filtre=titre&keys=';
  66.    CinefilBase = 'http://www.cinefil.com';
  67.    CinefilUrl  = CinefilBase + '/cinefil2005/';
  68.    crlf = #13#10;
  69. // pour mode debug
  70.    debug = False;                      // mode debug on/off
  71.    debugrep = 'd:\temp\';              // rΘpertoire de stockage des fichiers
  72.  
  73. var
  74.    MovieName, Line, EndStr, msgano: string;
  75.    viewstate, idhistoire, idavis, idgenerique, idanecdote: string;
  76.    BeginPos, EndPos: Integer;
  77.    filmok, FormatUTF8: Boolean;
  78.  
  79. //------------------------------------------------------------------------------
  80. // RECHERCHE DU FILM (Mr CinΘma)
  81. //------------------------------------------------------------------------------
  82. procedure AnalyzePageMrCinema(Address: string);
  83. var
  84.    Value, PageFilm, PageNext, PagePrev, urlFilm: String;
  85.  
  86. begin
  87. // attention aux positionnements: les textes sont au format UTF-8
  88. // note: actuellement, tous les films sont sur une seule page donc pas de pagenext/prev
  89.    filmok := False;
  90.    Line := GetPage(Address);
  91.    if debug then
  92.       SavePage(debugrep+'choixMrCinema.txt', Line);    // debug
  93.    Line := ExtrStr(Line, 'Vous effectuez une recherche sur', '<b> Articles  </b>');
  94.    if Line = '' then
  95.    begin
  96.       ShowMessage('Monsieur CinΘma: erreur lecture page de recherche');
  97.       exit;
  98.    end;
  99.    PickTreeClear;                                 // vide la liste des films
  100.    PickTreeAdd('Films (Monsieur CinΘma)', '');
  101.    urlFilm := '<a href="' + MrCinemaUrlFilm+'?id=';
  102.    repeat                                // mΘmo des films de cette page (if any)
  103.    BeginPos := Pos(urlFilm, Line);
  104.    if BeginPos > 0 then                             // 1 film trouvΘ
  105.    begin
  106.       filmok := True;                                // flag film(s) trouvΘ(s)
  107.       Delete(Line, 1, BeginPos - 1);                 // vire tout avant <a href=
  108.       Value := ExtrStr(Line, '', '<br>');            // Value = rΘfΘrence courante
  109.       Line := EndStr;                                // Line = la suite
  110.       PageFilm := GetUrl(urlFilm, Value, '');        // inclut &file=http
  111.       PickTreeAdd(FormatText(Value), PageFilm);
  112.    end;
  113.    until BeginPos = 0;                              // end repeat
  114.    if not(filmok) then 
  115.    begin
  116.       ShowMessage('Monsieur CinΘma: Aucun film trouvΘ pour "' + MovieName + '"')
  117.       exit;
  118.    end;
  119.    filmok := False;                         // remet α False jusqu'α la sΘlection 
  120.    if PageNext <> '' then
  121.       PickTreeAdd(' >> Page suivante', PageNext);
  122.    if PickTreeExec(Address) then
  123.    begin
  124.       if (Address = PageNext) or (Address = PagePrev) then
  125.       AnalyzePageMrCinema(Address)                   // page suivante/prΘcΘdente (if any)
  126.       else 
  127.       begin     
  128.          SetField(fieldURL, Address);
  129.          AnalyzeMoviePageMrCinema(Address);                            // page film
  130.       end;
  131.    end else
  132.       ShowMessage('Monsieur CinΘma: aucune page sΘlectionnΘe');   
  133. end;
  134.  
  135. //------------------------------------------------------------------------------
  136. // ANALYSE DE LA PAGE DU FILM (Mr CinΘma)
  137. //------------------------------------------------------------------------------
  138. procedure AnalyzeMoviePageMrCinema(Address: string);
  139.  
  140. var
  141.    Fullpage, PageEssentiel, PageHistoire, PageAvis, PageGenerique, PageAnecdote: string;
  142.    Value, Value2: string;
  143.    titreo, titret, realisateur, annee, producteur, duree, acteurs: string;
  144.  
  145. begin
  146. // attention aux positionnements: les textes sont au format UTF-8
  147.    Fullpage := GetPage(Address);          // charge la 1Φre page ("l'essentiel")
  148.    if debug then
  149.       SavePage(debugrep+'filmMrCinema.txt', Fullpage);    // debug
  150.    if Pos('<b>L''essentiel</b>', Fullpage) = 0 then
  151.    Begin
  152.       ShowMessage('Monsieur CinΘma: erreur lecture page film');
  153.       exit;
  154.    end;
  155.    filmok := True;                                         // τa y est, c'est bon
  156.    GetSubParms(Fullpage);      // rΘcupΦre les identifiants des pages secondaires
  157. // infos utiles de la page "essentiel"
  158.    PageEssentiel := ExtrStr(Fullpage, '<!-- Contenu des onglets -->', '</form>');
  159. //********** gΘnΘrique   
  160. //*** les infos du gΘnΘrique sont plus ou moins valorisΘes
  161. // si gΘnΘrique complet demandΘ
  162.    if (FullGenerique) and (idgenerique <> '') then
  163.    begin
  164.       PageGenerique := GetSubPage(Address, idgenerique, 'generiqueMrCinema');
  165. // titre Original/traduit
  166.       titret := ExtrStr(PageGenerique, '<b class="sous_titre">', '</b>');
  167.       titreo := ExtrStr(PageGenerique, '<span class="sous_titre">', '</span>');
  168. // sΘparer les 2 tables
  169.       Value := ExtrStr(PageGenerique, '<TABLE WIDTH=100%>', '</TABLE>');  // table des infos gΘnΘrales
  170.       acteurs := ExtrStr(EndStr, '<TABLE WIDTH=100%>', '</TABLE>');       // table des r⌠les/acteurs
  171. // acteurs
  172.       acteurs := FormatTable(acteurs);
  173.       acteurs := StringReplace(acteurs, '|', '-');
  174. // infos gΘnΘrales
  175. // si pas de sΘparateur de champs, alors on prend le mot suivant
  176. // d'o∙ la recherche sur des mots 'incomplets' (et en plus, τa permet de couvrir plus de cas...)
  177. // pas trΦs stricts dans leur codage, chez Mr CinΘma !!!!
  178.       Value := FormatTable(Value);
  179. // rΘalisateur et annΘe
  180.       realisateur := ExtrStr(Value, 'R├⌐alis', crlf);  // rΘalisation, rΘalisateur, rΘalisΘ,...
  181.       BeginPos := Pos('|', realisateur);
  182.       if BeginPos = 0 then
  183.          BeginPos := Pos(' ', realisateur);
  184.       realisateur := Copy(realisateur, BeginPos +1, length(realisateur));
  185.       annee := ExtrStr(realisateur, '(', ')');      // rq: pas toujours valorisΘe
  186.       realisateur := ExtrStr(realisateur,'', '(');
  187. // producteur
  188.       producteur := ExtrStr(Value, 'Produ', crlf);  // produit, production
  189.       BeginPos := Pos('|', producteur);
  190.       if BeginPos = 0 then
  191.          BeginPos := Pos(' ', producteur);
  192.       producteur := Copy(producteur, BeginPos +1, length(producteur));
  193. // durΘe
  194.       duree := ExtrStr(Value, 'Dur├⌐', crlf);      // durΘe, durΘes (oui, j'ai vu τa !!!)
  195.       BeginPos := Pos('|', duree);
  196.       if BeginPos = 0 then
  197.          BeginPos := Pos(' ', duree);
  198.       duree := Copy(duree, BeginPos +1, length(duree));
  199.       duree := ExtrStr(duree, '', 'minutes');
  200.    end;
  201. // si pas de gΘnΘrique complet ou champs non trouvΘs, on essaie dans la page 'essentiel'
  202. // titre Original/traduit
  203.    if titret = '' then
  204.       titret := ExtrStr(PageEssentiel, '<b class="sous_titre">', '</b>');
  205.    if titreo = '' then
  206.       titreo := ExtrStr(PageEssentiel, '<span class="sous_titre">', '</span>');
  207. // rΘalisateur
  208.    Value := ExtrStr(PageEssentiel, '<br>', '');
  209.    if realisateur = '' then
  210.       realisateur := ExtrStr(Value, 'de', '</a>');
  211. // annΘe
  212.    if annee = '' then
  213.    begin
  214.       annee := ExtrStr(Value, '</a>', 'avec');
  215.       annee := ExtrStr(annee, '(', ')');
  216.    end;
  217. // acteurs
  218.    if acteurs = '' then
  219.    begin
  220.       acteurs := ExtrStr(Value, 'avec', '<div');
  221.       acteurs := StringReplace(acteurs, ', ...', '');   // je ne sais pas si τa existe encore
  222.    end;
  223. // (pas d'info 'producteur' dans la page 'essentiel')
  224. //********** mise α jour des champs du gΘnΘrique
  225. // titre original et traduit
  226.    titret := FormatText(titret);                           // titre traduit ou original
  227.    titreo := StringReplace(titreo, '(', '');
  228.    titreo := StringReplace(titreo, ')', '');
  229.    titreo := FormatText(titreo);                           // original ou ''
  230.    if (titreo = '') or (titreo = titret) then             // 1er titre = original
  231.    begin                                                  // rq: pas de test Always
  232.       SetField(fieldOriginalTitle, titret);
  233.       SetField(fieldTranslatedTitle, '');   
  234.    end else
  235.    begin                                                  // traduit + original
  236.       SetField(fieldOriginalTitle, titreo);
  237.       SetField(fieldTranslatedTitle, titret); 
  238.    end;
  239. // rΘalisateur   
  240.    realisateur := FormatText(realisateur);
  241.    if (realisateur <> '') or Always then
  242.       SetField(fieldDirector, realisateur);
  243. // annΘe
  244.    if (annee <> '') or Always then
  245.       SetField(fieldYear, annee);
  246. // producteur
  247.    producteur := FormatText(producteur);
  248.    if (producteur <> '') or Always then
  249.       SetField(fieldProducer, producteur);
  250. // acteurs
  251.    acteurs := FormatText(acteurs);
  252.    if (acteurs <> '') or Always then
  253.       SetField(fieldActors, acteurs);
  254. // durΘe: SetField fait plus tard
  255. //********** Description (rΘsumΘ ou histoire complΦte)
  256.    Value := ExtrStr(PageEssentiel, '<div align="justify">', '</div>');     // rΘsumΘ
  257.    if (Value = '') or (Fullstory and (idhistoire <> '')) then 
  258.    begin                                // pas de rΘsumΘ ou histoire complΦte demandΘe
  259.       PageHistoire := GetSubPage(Address, idhistoire, 'histoireMrCinema');
  260.       Value := ExtrStr(PageHistoire, '<div align="justify">', '</div>');
  261.    end;
  262.    Value := FormatText(Value);
  263.    if (Value <> '') or Always then
  264.       SetField(fieldDescription, Value);
  265. //********** avis de la rΘdaction, note (peuvent Ωtre dans la page "essentiel") + anecdote
  266.    Value := '';
  267.    PageAvis := ExtrStr(Fullpage, '<b>L''avis de la r├⌐daction</b>' , '');
  268.    if (PageAvis = '') and (idavis <> '') then   // avis sur autre page
  269.       PageAvis := GetSubPage(Address, idavis, 'avisMrCinema');
  270.    Value := ExtrStr(PageAvis, '<div align="justify"><p>', '</div>');
  271.    Value := FormatText(Value);                   // Value = avis de la rΘdaction
  272.    Value2 := ExtrStr(PageAvis, '<img src="img/', 'redac.gif"');   // note 0 α 9 ou ''
  273.    if (Pos('<b>Aucun avis de la redaction.</b>', PageAvis) > 0) and (Value2 = '0') then
  274.       Value2 := '';                         // pas d'avis et img = 0redac.gif alors ignorer
  275.    if Value2 <> '' then                   
  276.       Value2 := IntToStr(StrToInt(Value2, 0) * 2);                   // note = 2 * x
  277.    if (Value2 <> '') or (Always) then               // note               
  278.       SetField(fieldRating, Value2); 
  279. // on ajoute l'anecdote si demandΘ et existant
  280.    if (ImportAnecdote) and (idanecdote <> '') then
  281.    begin
  282.       PageAnecdote := GetSubPage(Address, idanecdote, 'anecdoteMrCinema');
  283.       Value2 := ExtrStr(PageAnecdote, '<div align="justify">', '</div>');
  284.       Value2 := FormatText(Value2);
  285.       if Value2 <> '' then
  286.       begin
  287.          if Value <> '' then
  288.             Value := Value + crlf + crlf;
  289.          Value := Value + 'Anecdote' + crlf + Value2;
  290.       end;
  291.    end;
  292.    if (Value <> '') or Always then
  293.       SetField(fieldComments, Value);
  294. //********** hors zone dynamique
  295. // genre
  296.    Value := ExtrStr(Fullpage, '<b>Genre</b></div>', '</div>');
  297.    Value := FormatText(Value);
  298.    if (Value <> '') or Always then
  299.       SetField(fieldCategory, Value);
  300. // durΘe (sauf si dΘjα fait)
  301.    if duree = '' then
  302.    begin
  303.       duree := ExtrStr(Fullpage, '<b>Dur├⌐e</b></div>', '</div>');
  304.       duree := FormatText(duree);            // format hh:mm:ss α transformer en minutes
  305.       if duree <> '' then
  306.          duree := IntToStr(StrToInt(Copy(duree, 1, 2), 0) * 60 + StrToInt(Copy(duree, 4, 2), 0));
  307.    end;
  308.    if (duree <> '') or Always then
  309.       SetField(fieldLength, duree);
  310. // pays
  311.    Value := ExtrStr(Fullpage, '<b>Pays </b></div>', '</span>');
  312.    Value := FormatText(Value);
  313.    if (Value <> '') or Always then
  314. // pas toujours trΦs cohΘrents les noms de pays...
  315.       Value := StringReplace(Value, 'Usa', 'Etats-unis');
  316.       Value := StringReplace(Value, 'U.s.a', 'Etats-unis');
  317.       Value := StringReplace(Value, 'usa', 'Etats-unis');
  318.       Value := StringReplace(Value, 'Etats unis', 'Etats-unis');
  319.       Value := StringReplace(Value, 'Grande-bretagne', 'Grande bretagne');
  320.       SetField(fieldCountry, Value);
  321. //********** image si demandΘe (pas de test Always)
  322.    if (ImportPicture = 1) or (ImportPicture = 3) then
  323.    begin
  324.       Value := ExtrStr(Fullpage, '<div style="border-left:1px solid #ffffff;border-right:1px solid #ffffff;">', '<br>');
  325.       Value := ExtrStr(Value, '<img src="', '"');
  326.       if Value <> '' then
  327.          GetPicture(Value, ExternalPictures);
  328.    end;
  329. end;
  330.  
  331. //------------------------------------------------------------------------------
  332. // RECHERCHE DU FILM (cinΘfil)
  333. //------------------------------------------------------------------------------
  334. procedure AnalyzePageCinefil(Address: string);
  335. var
  336.    Page: TStringList;
  337.    Value,Value2,page_film,titre_film, annee_film,PagePrev,PageNext: string;
  338.  
  339. begin
  340.    filmok := False;
  341.    msgano := '';
  342.    PickTreeClear;                                       //vide la liste des films
  343.    PickTreeAdd('Films (CinΘfil)', '');
  344.    Line := GetPage(Address);
  345.    if debug then
  346.       SavePage(debugrep+'choixCinefil.txt', Line);    // debug
  347.    Value := ExtrStr(Line, '<B> RΘsultat ', '</B>');
  348.    if Value = '' then
  349.    begin
  350.       msgano := 'erreur lecture page de recherche';         // non trouvΘ = erreur
  351.       exit;
  352.    end;
  353.    if Copy(Value, 1, 1) = '0' then                              // 0 = aucun film
  354.    begin
  355.       msgano := 'aucun film trouvΘ: essayez autre chose';   
  356.       exit; 
  357.    end; 
  358.  
  359. // recherche pages prΘcΘdente et suivante
  360.    Line := ExtrStr(Line, 'RΘsultat', '');
  361.    Value := ExtrStr(Line, '', '</TD>');              // Value = les url des pages
  362.    if Pos('HREF', UpperCase(Value)) = 0 then
  363.       Value := '';                                     // 1 seule page 
  364.    while Value <> '' do
  365.    begin   
  366.    Value2 := ExtrStr(Value, '', '/a>');               // Value2 = url page xxx
  367.    Delete(Value, 1, Pos('</a>', Value)+4);            // Value = les suivantes
  368. // ignorer les "retours rapides" (<< et >>) pour ne pas confondre avec < et > 
  369.    if Pos('><<<', Value2) > 0 then
  370.       continue; 
  371.    if Pos('>>><', Value2) > 0 then
  372.       continue; 
  373.    if Pos('><<', Value2) > 0 then           
  374.    begin                                          // Value2 = url page prΘcΘdente
  375.       PagePrev := GetUrl('', Value2, CinefilBase);
  376.       PickTreeAdd('<<< page prΘcΘdente', PagePrev);
  377.    end;
  378.    if Pos('>><', Value2) > 0 then
  379.       PageNext := GetUrl('', Value2, CinefilBase);   // Value2 = url page suivante 
  380.    end;                                              // end do while value <> ''
  381. // mΘmo des films de cette page
  382.    Value := '<font class=noir>';                           // sΘparateur de films
  383.    repeat
  384. // cherche le lien de la page du film
  385.    BeginPos := Pos(Value, Line);                              // description film
  386.    if BeginPos > 0 then                                          // 1 film trouvΘ
  387.    begin
  388.       Delete(Line, 1, BeginPos-1);
  389. // url de la page
  390.       page_film := GetUrl('HREF=''../fichefilm.cfm?ref=', Line, CinefilUrl);
  391. // annΘe
  392.       annee_film := FormatText(ExtrStr(Line, Value, ' '));
  393. // nom du film et rΘalisateur
  394.       BeginPos := Pos('TITLE="', UpperCase(Line));
  395.       Delete(Line, 1, BeginPos);
  396.       titre_film := ExtrStr(Line, '">', '</TD>');
  397.       titre_film := StringReplace(titre_film, '</a>', ',');   // titre, rΘalisateur
  398.       titre_film := FormatText(titre_film);
  399. // ajoute le film
  400.       PickTreeAdd(titre_film + ' ' + annee_film , page_film);
  401.    end;
  402.    until BeginPos = 0;
  403.    if PageNext <> '' then
  404.       PickTreeAdd('>>> page suivante', PageNext);     
  405.    if PickTreeExec(Address) then
  406.    begin
  407.       if (Address = PageNext) or (Address = PagePrev) then
  408.          AnalyzePageCinefil(Address)                    // page suivante/prΘcΘdente
  409.       else 
  410.          AnalyzePageFilmCinefil(Address);                            // page film
  411.    end else
  412.       msgano := 'Vous n''avez rien sΘlectionnΘ';
  413. end;
  414.  
  415. //------------------------------------------------------------------------------
  416. // ANALYSE DE LA PAGE DU FILM (CinΘfil)
  417. //------------------------------------------------------------------------------
  418. procedure AnalyzePageFilmCinefil(Address: string);
  419. var
  420.    Value,Value2,Value3,img: string;
  421.  
  422. begin
  423.    filmok := True;
  424.    Line := GetPage(Address);
  425.    Line := ExtrStr(Line, 'RΘfΘrence film cinefil', '');          // vire le dΘbut
  426.    if debug then
  427.       SavePage(debugrep+'filmCinefil.txt', Line);    // debug
  428. // rq: pas de test Always
  429. // image: test s'il y a un grand format
  430.    img := ExtrStr(Line, 'javascript:ZoomPhoto(''', '''');
  431.    if img = '' then                        // sinon test s'il y a un petit format
  432.       img := ExtrStr(Line, '<IMG class=photo SRC=''', '''');     
  433.    if img <> '' then 
  434.       GetPicture(img, ExternalPictures)
  435.    else                       
  436.       ShowMessage('CinΘfil: pas d''affiche prΘvue pour "' + MovieName + '"');
  437. end;
  438.  
  439. //------------------------------------------------------------------------------
  440. // formatage d'un texte pour affichage
  441. // suppression des tags html, remplacement des caractΦres bizarres
  442. //------------------------------------------------------------------------------
  443. function FormatText(str1: string) :string;
  444. var
  445.    s: string;
  446.  
  447. begin
  448.    if FormatUTF8 then
  449.       str1 := UTF8Decode(str1);                  // UTF-8 en ASCII
  450. // les caractΦres spΘciaux (pour Θviter de confondre avec les tags HTML)
  451.    str1 := StringReplace(str1, '&', '&');
  452.    str1 := StringReplace(str1, '<', '<');
  453.    str1 := StringReplace(str1, '>', '>');
  454.    str1 := StringReplace(str1, '"', '"');
  455. // dΘbut et fin de paragraphe = retour α la ligne
  456.    str1 := StringReplace(str1, '</p>', crlf);
  457.    str1 := StringReplace(str1, '<p>', crlf);
  458.    HTMLRemoveTags(str1);                     // supprime les tags HTML
  459.    HTMLDecode(str1);                         // et les caractΦres spΘciaux
  460. // supprimer les caractΦres de formatage en dΘbut de chaine (code ASCII <= x'20')
  461.    repeat
  462.    s := Copy(str1, 1, 1);                   // 1er caractΦre de str1
  463.    if s <= #32 then
  464.       Delete(str1, 1, 1);                    // on le vire
  465.    until (s = '') or (s > #32);
  466. // et on supprime les doubles crlf
  467.    str1 := StringReplace(str1, crlf+crlf, crlf);
  468. // correction des caractΦres ASCII Θtendu qui passent mal
  469. // probablement un pb de police car c'est OK avec ShowMessage
  470. // ranges x'81' α x'90'  et x'93' α x'9F'
  471. // les caractΦres non translatΘs sont des caractΦres rarissimes !!!!
  472.    str1 := StringReplace(str1, chr(130), ',');
  473.    str1 := StringReplace(str1, chr(132), ',,');
  474.    str1 := StringReplace(str1, chr(133), '...');
  475.    str1 := StringReplace(str1, chr(136), '^');       // ouais
  476.    str1 := StringReplace(str1, chr(139), '<');
  477.    str1 := StringReplace(str1, chr(140), 'OE');
  478.    str1 := StringReplace(str1, chr(147), chr(171));  // quotes ouvrantes
  479.    str1 := StringReplace(str1, chr(148), chr(187));  // quotes fermantes
  480.    str1 := StringReplace(str1, chr(150), '-');
  481.    str1 := StringReplace(str1, chr(151), '--');
  482.    str1 := StringReplace(str1, chr(152), '"');
  483.    str1 := StringReplace(str1, chr(155), '>');
  484.    str1 := StringReplace(str1, chr(156), 'oe');
  485. // fin des corrections de caractΦres
  486.    result := Trim(str1);
  487. end;
  488.  
  489. //------------------------------------------------------------------------------
  490. // formatage d'une table (MrCinΘma-gΘnΘrique)
  491. //------------------------------------------------------------------------------
  492. function FormatTable(str1: string) :string;
  493. var
  494.    sepcel: string;
  495.    
  496. begin
  497. // structure table
  498. // <TR ...>                      = dΘbut de ligne
  499. //   <TD ...> texte </TD>        = 1 cellule
  500. // </TR>                         = fin de ligne
  501.    str1 := StringReplace(str1, crlf, '');         // supprimer les crlf
  502.    str1 := StringReplace(str1, '<TR>', crlf);     // dΘbut de ligne = crlf
  503.    str1 := StringReplace(str1, '<TR ', crlf+'<');
  504.    str1 := StringReplace(str1, '<TD>', '|');      // cellule du 'milieu'
  505.    str1 := StringReplace(str1, '<TD ', '░<');     // 1Φre cellule
  506.    HTMLRemoveTags(str1);                          // supprimer les autres tags
  507.    str1 := StringReplace(str1, '░'+crlf, '');     // supprimer les lignes vides
  508. // dΘterminer le 1er sΘparateur de cellule
  509. // crlf░  = <TR><TD ...>texte
  510. // crlf░| = <TR><TD ...></TD><TD>texte
  511. // et le remplacer par crlf (α priori seuls cas possibles)
  512.    sepcel := crlf+'░|';
  513.    if Pos(sepcel, str1) <> 1 then
  514.       sepcel := crlf+'░';
  515.    str1 := StringReplace(str1, sepcel, crlf);
  516. // s'il reste des crlf|| ou crlf|, il s'agit de continuations de lignes
  517.    str1 := StringReplace(str1, crlf+'||', ' ');   // 1 blanc pour ne pas coller au prΘcΘdent
  518.    str1 := StringReplace(str1, crlf+'|', ' ');
  519.    str1 := StringReplace(str1, '||', '|');        // supprimer les cellules vides       
  520.    str1 := StringReplace(str1, '||', '|');        // oui, c'est voulu
  521.    str1 := StringReplace(str1, '|', ' | ');       // decoller les sΘparateurs du texte
  522.    str1 := StringReplace(str1, '  ', ' ');        // virer les boubles blancs
  523.    str1 := StringReplace(str1, '░', '');          // et celui qui reste
  524.    result := str1;         // le crlf en tΩte, il sera supprimΘ dans FormatText
  525. end;
  526.  
  527. //------------------------------------------------------------------------------
  528. // formatage du nom de film
  529. // les moteurs n'aiment pas les caractΦres accentuΘs, les apostrophes, la ponctuation
  530. //------------------------------------------------------------------------------
  531. function FormatMovieName(str1: string) :string;
  532.  
  533. begin
  534. // str1 est en ASCII dans tous les cas
  535.    str1 := AnsiLowerCase(str1);                // en minuscules
  536.    str1 := StringReplace(str1, '''', ' '); 
  537.    str1 := StringReplace(str1, '"', ' ');
  538.    str1 := StringReplace(str1, '.', '');
  539.    str1 := StringReplace(str1, '!', '');
  540.    str1 := StringReplace(str1, '?', '');
  541.    str1 := StringReplace(str1, ',', ' ');
  542.    str1 := StringReplace(str1, '-', ' ');
  543.    str1 := StringReplace(str1, ':', ' ');
  544.    str1 := StringReplace(str1, ';', ' ');
  545.    str1 := StringReplace(str1, '/', ' ');
  546.    str1 := StringReplace(str1, 'α', 'a');
  547.    str1 := StringReplace(str1, 'Σ', 'a');
  548.    str1 := StringReplace(str1, 'Γ', 'a');
  549.    str1 := StringReplace(str1, 'τ', 'c');    
  550.    str1 := StringReplace(str1, 'Θ', 'e');   
  551.    str1 := StringReplace(str1, 'Φ', 'e');
  552.    str1 := StringReplace(str1, 'δ', 'e');
  553.    str1 := StringReplace(str1, 'Ω', 'e');
  554.    str1 := StringReplace(str1, '∩', 'i');
  555.    str1 := StringReplace(str1, '⌠', 'o');
  556.    str1 := StringReplace(str1, '∙', 'u');
  557.    str1 := StringReplace(str1, 'ⁿ', 'u'); 
  558.    str1 := StringReplace(str1, '√', 'u');
  559.    result := str1;
  560. end;
  561.  
  562. //------------------------------------------------------------------------------
  563. // extraction d'une url contenue dans une chaine de caractΦres sans Θdition
  564. // adr := GetUrl(texte_HREF_cherchΘ,chaine,url_de_base)
  565. //------------------------------------------------------------------------------
  566. function GetUrl(strfrom,str1,urlb: string) :string;
  567. var
  568.    i: Integer;
  569.    delim: String;
  570.  
  571. begin
  572.    if strfrom <> '' then                   // si from = '' on part du dΘbut
  573.    begin
  574.       i := Pos(strfrom, str1);               // position href cherchΘ
  575.       if i = 0 then                         // rien trouvΘ
  576.       begin
  577.          result := '';
  578.          exit;
  579.       end; 
  580.       Delete(str1,1, i -1);
  581.    end; 
  582.    i := Pos('HREF=', UpperCase(str1));        // debut url: href= 
  583.    delim := Copy(str1, i+5, 1);               // dΘlimiteur = " ou '
  584.    Delete(str1,1, i +5);
  585.    i := Pos(delim, str1);   
  586.    if i > 0 then
  587.       Delete(str1,i, Length(str1));
  588.     str1 := StringReplace(str1, '&', '&');
  589.    str1 := StringReplace(str1, '../', '');    // cf adresse relative
  590.    str1 := StringReplace(str1, './', '');     
  591.    str1 := urlb + str1;                       // ajoute url de base   
  592.    result := Trim(str1);
  593. end;
  594.  
  595. //------------------------------------------------------------------------------
  596. // extraction de la chaine dΘlimitΘe par strfrom et strto dans str1
  597. // en sortie: variable globale EndStr = fin de la chaine α partir de strto
  598. //------------------------------------------------------------------------------
  599. function ExtrStr(str1,strfrom,strto: string) :string;
  600. var
  601.    i: Integer;
  602.  
  603. begin
  604.    EndStr := '';
  605.    if strfrom <> '' then                         // si from = '' on part du dΘbut
  606.    begin
  607.       i := Pos(strfrom, str1);
  608.       if i = 0 then                               // from non trouvΘ
  609.       begin
  610.          result := '';
  611.          exit;
  612.       end; 
  613.       Delete(str1, 1, i + Length(strfrom) -1);
  614.    end; 
  615.    i := Pos(strto, str1);                         // fin de la chaine
  616.    EndStr := Copy(str1, i, Length(str1));
  617.    Delete(str1, i, Length(str1));
  618.    result := Trim(str1);
  619. end;
  620.       
  621. //------------------------------------------------------------------------------
  622. // rΘcupΘration des identifiants 'sous-pages' (MrCinema)
  623. // GetSubParms(page)
  624. //------------------------------------------------------------------------------
  625. procedure GetSubParms(s: string);
  626. var
  627.    Value: string;
  628.       
  629. begin
  630.    Value := ExtrStr(s, '<!-- Onglet fils (2nde ligne) -->', '</TD></TR>');  // infos utiles
  631.    if Pos('doPostBack', Value) > 0 then
  632.    begin                                                       // formulaire et PostPage
  633. // rΘcupΦre le paramΦtre VIEWSTATE (ident de session)
  634.       viewstate := ExtrStr(s, 'name="__VIEWSTATE"', '/>');
  635.       viewstate := ExtrStr(viewstate, 'value="', '"');
  636. // c'est un peu trop cablΘ: ordre et __EVENTARGUMENT='': serait mieux si c'Θtait plus prΘcis
  637. // page histoire
  638.       idhistoire := ExtrStr(Value, '__doPostBack(''', '''');
  639.       Value := EndStr;
  640.       if idhistoire <> '' then
  641.       begin
  642.          idhistoire := StringReplace(idhistoire, '$', ':');
  643.          idhistoire := '__EVENTTARGET='+ idhistoire + '&__EVENTARGUMENT=&__VIEWSTATE=' + viewstate;
  644.       end;
  645. // page avis de la rΘdaction
  646.       idavis := ExtrStr(Value, '__doPostBack(''', '''');
  647.       Value := EndStr;
  648.       if idavis <> '' then
  649.       begin
  650.          idavis := StringReplace(idavis, '$', ':');
  651.          idavis := '__EVENTTARGET='+ idavis + '&__EVENTARGUMENT=&__VIEWSTATE=' + viewstate;
  652.       end;
  653. // page gΘnΘrique
  654.       idgenerique := ExtrStr(Value, '__doPostBack(''', '''');
  655.       Value := EndStr;
  656.       if idgenerique <> '' then
  657.       begin
  658.          idgenerique := StringReplace(idgenerique, '$', ':');
  659.          idgenerique := '__EVENTTARGET='+ idgenerique + '&__EVENTARGUMENT=&__VIEWSTATE=' + viewstate;
  660.       end;
  661. // page anecdote
  662.       idanecdote := ExtrStr(Value, '__doPostBack(''', '''');
  663.       if idanecdote <> '' then
  664.       begin
  665.          idanecdote := StringReplace(idanecdote, '$', ':');
  666.          idanecdote := '__EVENTTARGET='+ idanecdote + '&__EVENTARGUMENT=&__VIEWSTATE=' + viewstate;
  667.       end;
  668.    end
  669.    else
  670.    begin                                                       // url normale
  671. // page histoire
  672.       idhistoire := ExtrStr(Value,'', '</a>');
  673.       Value := EndStr;
  674.       idhistoire := GetUrl('', idhistoire, MrCinemaUrlFilm);
  675. // page avis de la rΘdaction
  676.       idavis := ExtrStr(Value,'<TD>', '</a>');
  677.       Value := EndStr;
  678.       idavis := GetUrl('<TD>', idavis, MrCinemaUrlFilm);
  679. // page gΘnΘrique
  680.       idgenerique := ExtrStr(Value,'<TD>', '</a>');
  681.       Value := EndStr;
  682.       idgenerique := GetUrl('', idgenerique, MrCinemaUrlFilm);
  683. // page anecdote
  684.       idanecdote := ExtrStr(Value,'<TD>', '</a>');
  685.       idanecdote := GetUrl('', idanecdote, MrCinemaUrlFilm);
  686.    end;
  687. end;
  688.  
  689. //------------------------------------------------------------------------------
  690. // rΘcupΘration des 'sous-pages' (MrCinema)
  691. // pagexxx := GetSubPage(adresse_fiche_film, ident_page_cherchΘe, nom_fichier_pour_debug)
  692. //------------------------------------------------------------------------------
  693. function GetSubPage(Address, idpage, idfic: string) :string;
  694. begin
  695.    idpage := UrlEncode(idpage);
  696.    if viewstate = '' then
  697.       result := GetPage(idpage)
  698.    else
  699.    begin
  700. // formulaire et PostPage
  701. // encore des caractΦres α transformer... aprΦs UrlEncode (ordre trΦs important)
  702.       idpage := StringReplace(idpage, '+', '%2B');
  703.       idpage := StringReplace(idpage, ':', '%3A');
  704.       result := PostPage(Address,idpage);
  705.    end;
  706.    if debug then
  707.       SavePage(debugrep+idfic+'.txt', result);    // debug
  708. // ne garder que la partie dynamique
  709.    result := ExtrStr(result, '<!-- Contenu des onglets -->', '</form>');
  710. end;
  711.    
  712. //------------------------------------------------------------------------------
  713. // Θcriture d'une chaine sur disque (pour debug...)
  714. // SavePage(chemin_du_fichier,chaine)
  715. // chemin_du_fichier = chemin complet ex: 'c:\temp\monfichier.txt'
  716. // note: pour bien visualiser l'UTF-8, utiliser un Θditeur genre SciTe
  717. //------------------------------------------------------------------------------
  718. procedure SavePage(fic, str1: string);
  719. var
  720.    Page2: TStringList;
  721.  
  722. begin
  723.    page2 := TStringList.Create;
  724.    page2.Text := str1;
  725.    page2.SaveToFile(fic);
  726.    page2.Free;
  727. end;
  728.  
  729. //------------------------------------------------------------------------------
  730. //  c'est ici que τa commence 
  731. //------------------------------------------------------------------------------                                               
  732. begin
  733.    if CheckVersion(3,4,3) then
  734.    begin
  735. // en rΦgle gΘnΘrale, c'est mieux de passer le nom du film en franτais
  736. // Monsieur cinΘma 
  737.       FormatUTF8 := True;                            // pages au format UTF-8
  738.       MovieName := GetField(fieldTranslatedTitle);
  739.       if MovieName = '' then
  740.          MovieName := GetField(fieldOriginalTitle);
  741.       if Input('MonsieurCinΘma.com Import', 'Entrez le titre du film :', MovieName) then
  742.       begin
  743.          MovieName := FormatMovieName(MovieName);
  744.          AnalyzePageMrCinema(MrCinemaUrlLook + UrlEncode(MovieName));
  745.          if (ImportPicture = 2) or (ImportPicture = 3) then   // si image de cinΘfil demandΘe
  746.          begin
  747. // si filmok = False ou MovieName non valorisΘ c'est que MrCinema n'a rien trouvΘ
  748.             FormatUTF8 := False;                     // pages au format ASCII
  749.             MovieName := GetField(fieldTranslatedTitle);
  750.             if MovieName = '' then
  751.                MovieName := GetField(fieldOriginalTitle);
  752.             if (filmok) and (MovieName <> '') then
  753.             begin
  754.                repeat
  755.                MovieName := FormatMovieName(MovieName);
  756.                AnalyzePageCinefil(CinefilUrl + 'CFM_Recherches/films.cfm?lachaine2=' + UrlEncode(MovieName));       
  757.                if not(filmok) then
  758.                begin                               // page non trouvΘe ou erreur
  759.                   if not(Input('CinΘfil.com Import', msgano, MovieName)) then
  760.                      filmok := True;              // non saisie: on sort
  761.                end;
  762.                until filmok;
  763.             end;                                    // end MovieName ok MrCinema
  764.          end;                                        // end test ImportPicture
  765.          if filmok then
  766.             DisplayResults;
  767.       end;                                            // end saisie ok MrCinema
  768.    end else
  769.       ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.3)');
  770. end.
  771.